return function(BOXUI)

local utils = BOXUI.utils

local M = utils.newclass("button")
local mt = M

M.init = function(self, x, y, width, height)
	self.theme = BOXUI.theme
	self.x, self.y = x, y
	self.width, self.height = width, height
	
	self.checked = false
	self.checkbox = false
	self.radiogroup = nil
	self.active = nil
	self.selected = nil
	self.onClick = nil
	self.font = love.graphics.getFont()
	self.draw = self.theme.draw.button
end

M.refresh = function(self)
	self.draw = self.theme.draw.button
end

M.wheelmoved = function(self, x, y, dx, dy)
end

M.mousemoved  = function(self, x, y, button)
	--self.active = true
end

M.mousepressed  = function(self, x, y, button)
	self.selected = button == 1 and self.active
end

M.mousereleased  = function(self, x, y, button)
	if self.active and self.selected then
		if self.onClick then self.onClick(self) end
		if self.radiogroup then 
			for k, v in pairs(self.radiogroup) do
				v.checked = false
			end
			self.checked = true
		elseif self.checkbox then
			self.checked = not self.checked
		end
	end
	self.selected = false
end

M.update = function(self, dt)
end

M.focus = function(self) self.active = true end
M.unfocus = function(self) self.active = false end

BOXUI.add(M)
end

